package com.woniuxy.stage3demo.service.chenyxuanService.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.chenyuxuanBean.EntranceRuleBean;
import com.woniuxy.stage3demo.mapper.chenyuxuanMapper.EntranceRuleMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.chenyxuanService.EntranceRuleService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional(readOnly = true)
@Service
public class EntranceRuleServiceImpl implements EntranceRuleService {

    @Resource
    private EntranceRuleMapper entranceRuleMapperImpl;


    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int addEntranceRule(EntranceRuleBean entranceRuleBean) {
        return entranceRuleMapperImpl.addEntranceRule(entranceRuleBean);
    }


    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int deleteEntranceRule(int id) {
       return entranceRuleMapperImpl.deleteEntranceRule(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateEntranceRule(EntranceRuleBean entranceRuleBean) {
       return entranceRuleMapperImpl.updateEntranceRule(entranceRuleBean);
    }


    @Override
    public EntranceRuleBean findEntranceRuleByContext(EntranceRuleBean entranceRuleBean) {
        return entranceRuleMapperImpl.findEntranceRuleByContext(entranceRuleBean);
    }

    @Override
    public PageInfo<EntranceRuleBean> findAllEntranceRule(PageRequest pageRequest, EntranceRuleBean entranceRuleBean) {
        return PageHelper.startPage( pageRequest.getPageNum(),pageRequest.getLimit()).
                doSelectPageInfo(() -> entranceRuleMapperImpl.findAllEntranceRule(pageRequest,entranceRuleBean));
    }
}
